/**
 * Created by Administrator on 2017/8/10.
 */

import React ,{ Component }from 'react'
import {View, Image ,StyleSheet ,TextInput,Dimensions,Text,TouchableOpacity,ToastAndroid} from 'react-native'
import {NavigationActions} from 'react-navigation'
import StorageUtils from '../Storage/StorageUtil'

const splashImg = require('../Img/splash_new.png')
const resetHostAction = NavigationActions.reset({
    index: 0,
    actions: [
        NavigationActions.navigate({ routeName: 'Host'})
    ]
})

const resetLoginAction = NavigationActions.reset({
    index: 0,
    actions: [
        NavigationActions.navigate({ routeName: 'Login'})
    ]
})

export default class Splash extends Component{

    static navigationOptions = ({navigation}) =>({
        headerStyle:{
            height:0
        }
    })

    constructor(props){
        super(props)
        this.state = {
            userInfo:null
        }
    }

    render(){
        return(
            <Image style={{width:'100%',height:'100%',resizeMode:'cover'}} source={splashImg}/>
        )
    }

    componentWillMount() {
        StorageUtils._load('loginresult',(params)=>{
            this.setState({userInfo:params})
            GLOBAL.token = params.data['ww-token']
        })
    }

    componentDidMount() {
        this.timer = setTimeout(
            () => {
                console.log('牛逼：'+this.state.userInfo)
                if(this.state.userInfo!=null){
                    this.props.navigation.dispatch(resetHostAction)
                }else {
                    this.props.navigation.dispatch(resetLoginAction)
                }
            },
            3000
        );
    }

    componentWillUnmount() {
        this.timer && clearTimeout(this.timer);
    }
}



